package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.model.SignfaultEntity;
import com.hualude.roadsign.service.SignfaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by xu-jiaHui on 2017/2/28.
 */
@Controller
@RequestMapping("/rds_fault")
public class SignfaultController {
    @Resource
    private SignfaultService signfaultService;

    @RequestMapping(value = "/getFault4DT")
    @ResponseBody
    public DTResponseDto getSignfault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer gActorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signfaultService.getSignfault4DT(dtRequestDto, actorId, gActorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }


    @RequestMapping(value = "/deleteFaultReportByIds")
    @ResponseBody
    public JsonMsgDto deleteFaultReportByIds(String FaultReportIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.deleteFaultReportByIds(FaultReportIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/updateSignFaultById")
    @ResponseBody
    public JsonMsgDto updateSignFaultById(Integer signFaultId, Integer signFaultLevel, Integer signFaultType, String signFaultPic,
                                          String signFaultReason, Double repairAmount) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.updateSignFaultById(signFaultId, signFaultLevel, signFaultType, signFaultPic,
                    signFaultReason, repairAmount));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getlongLatitude4Map")
    @ResponseBody
    public List<RoadpoleDto> getlongLatitude4Map(Integer roadSignId) throws Exception {
        List<RoadpoleDto> roadpoleDtos = new ArrayList<RoadpoleDto>();
        try {
            roadpoleDtos = signfaultService.getlongLatitude4Map(roadSignId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return roadpoleDtos;
    }

    @RequestMapping(value = "/signFaultAudit")
    @ResponseBody
    public JsonMsgDto signFaultAudi(Integer isPass, String signFaultCheckBack, Integer signFaultId, Integer actorId, String signCheckTime, Integer maintenancePeopleId, Integer userId, Integer roadSignId, String signFaultReason, Integer signFaultLevel, Integer signFaultType, String signFaultPic, String signFaultTime, Double repairAmount) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.signFaultAudit(isPass, signFaultCheckBack, signFaultId, actorId, signCheckTime, maintenancePeopleId, userId, roadSignId, signFaultReason, signFaultLevel, signFaultType, signFaultPic, signFaultTime, repairAmount));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/signFaultAudit2Report")
    @ResponseBody
    public JsonMsgDto signFaultAudit2Report(Integer isPass, String signFaultCheckBack, Integer signFaultId, Integer actorId, String signCheckTime, Integer maintenancePeopleId, Integer signFaultPeopleId, Integer userId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.signFaultAudit2Report(isPass, signFaultCheckBack, signFaultId, actorId, signCheckTime, maintenancePeopleId, signFaultPeopleId, userId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getCurrentFault4DT")
    @ResponseBody
    public DTResponseDto getCurrentFault4DT(DTRequestDto dtRequestDto, Integer actorId, String maintenancePeopleName) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signfaultService.getCurrentFault4DT(dtRequestDto, actorId, maintenancePeopleName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }


    @RequestMapping(value = "/getOrgAndUserByUserId")
    @ResponseBody
    public JsonMsgDto getOrgAndUserByUserId(Integer signFaultPeopleId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.getOrgAndUserByUserId(signFaultPeopleId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getFaultList")
    @ResponseBody
    public JsonMsgDto getFaultList(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size)
            throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.getFaultList(orgId, actorIds, faultStatus, count, size));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/reportSignFault")
    @ResponseBody
    public JsonMsgDto reportSignFault(Integer roadSignId, Integer signFaultPeopleId, Integer signFaultLevel, Integer signFaultType,
                                      String signFaultPic, String signFaultReason, Double repairAmount, Integer orgId, Integer mainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            signfaultService.reportSignFault(roadSignId, signFaultPeopleId, signFaultLevel, signFaultType,
                    signFaultPic, signFaultReason, repairAmount, orgId, mainOrgId);
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignfaultInfoByRoadSignId")
    @ResponseBody
    public List<SignfaultEntity> getSignfaultInfoByRoadSignId(Integer roadSignId) throws Exception {
        List<SignfaultEntity> signfaultDtos = new ArrayList<SignfaultEntity>();
        try {
            signfaultDtos = signfaultService.getSignfaultInfoByRoadSignId(roadSignId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return signfaultDtos;
    }

    @RequestMapping(value = "/updateSignFault2fail")
    @ResponseBody
    public JsonMsgDto updateSignFault2fail(Integer signFaultId, Integer status, String signFaultCheckBack, Integer userId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.updateSignFault2fail(signFaultId, status, signFaultCheckBack, userId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/updateSignFault2success")
    @ResponseBody
    public JsonMsgDto updateSignFault2success(Integer signFaultId, Integer status, String signFaultCheckBack, Integer userId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.updateSignFault2success(signFaultId, status, signFaultCheckBack, userId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignFaultInfOByUserIdStatus")
    @ResponseBody
    public JsonMsgDto getSignFaultInfOByUserIdStatus(Integer userId,
                                                     String actorIds,
                                                     Integer count,
                                                     Integer size,
                                                     Integer status) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.getSignFaultInfOByUserIdStatus(userId, actorIds, count, size, status));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getRejectedFault4DT")
    @ResponseBody
    public DTResponseDto getRejectedFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signfaultService.getRejectedFault4DT(dtRequestDto, actorId, userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/updateSignFaultCheckById")
    @ResponseBody
    public JsonMsgDto updateSignFaultCheckById(Integer isPass, Integer signFaultId, Integer actorId, Integer companyCheck, Integer mainCheck, String signCheckTime) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signfaultService.updateSignFaultCheckById(isPass, signFaultId, actorId, companyCheck, mainCheck, signCheckTime));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignFaultUnAuditCount")
    @ResponseBody
    public JsonMsgDto getSignFaultUnAuditCount(Integer actorId, Integer gActorId, Integer userId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.getSignFaultUnAuditCount(actorId, gActorId, userId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignInfoBySignId")
    @ResponseBody
    public JsonMsgDto getSignInfoBySignId(Integer roadSignId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.getSignInfoBySignId(roadSignId));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignFaultCount")
    @ResponseBody
    public JsonMsgDto getSignFaultCount(Integer orgId, Integer actorId, Integer userId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.getSignFaultCount(orgId, actorId, userId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getOrg4Select")
    @ResponseBody
    public JsonMsgDto getOrg4Select(Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.getOrg4Select(actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/updateRoadSignAndPoleSecurity")
    @ResponseBody
    public JsonMsgDto updateRoadSignAndPoleSecurity(Integer roadSignId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.updateRoadSignAndPoleSecurity(roadSignId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getCheckBackBySignFaultId")
    @ResponseBody
    public JsonMsgDto getCheckBackBySignFaultId(Integer roadSignId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.getCheckBackBySignFaultId(roadSignId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignFaultStatus")
    @ResponseBody
    public JsonMsgDto getSignFaultStatus(Integer signFaultId, Integer roadSignId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signfaultService.getSignFaultStatus(signFaultId, roadSignId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

}
